#include <iostream>
#include <vector>
#include "deserializer.h"
#include <arpa/inet.h>
#include <netdb.h>

using namespace std;

vector<A*> A :: a_objects = vector<A*>();
vector<B*> B :: b_objects = vector<B*>();

int talk_with_server(int socket,const char * buffer, int buf_size) {
	cout << buffer << " sended" << endl;
	int size = send(socket, buffer, buf_size, 0);
	if(size <= 0) {
		if(size < 0)
			return -1;
	}
	return 0;
}


int main(int argc, char ** argv) {
	hostent *host = gethostbyname(argv[1]);
	if(host == NULL) { perror("wrong host name");}
	
	int remote_server_sckt = socket(AF_INET, SOCK_STREAM, 0);
	sockaddr_in *remote_server = new sockaddr_in;
	remote_server->sin_family = AF_INET;
	remote_server->sin_addr.s_addr = ((in_addr*)host->h_addr)->s_addr; 
	remote_server->sin_port = htons(atoi(argv[2]));
	
	int errcheck = connect(remote_server_sckt,(sockaddr*)remote_server,sizeof(sockaddr_in));
	
	A a = A();
	B b = B();
	
	string a_str = a.serialize();
	string b_str = b.serialize();
	
	talk_with_server(remote_server_sckt, a_str.c_str(), a_str.size());
	talk_with_server(remote_server_sckt, b_str.c_str(), b_str.size()); 
}
